﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include "NdbDataSchema.h"
#include "GbmpQuickCast.h"

#define REGISTER_UNSERIALIZATION_BEHAVIOR(DbObjectGuid, pUnserializationBehavior) \
    static void __Func##DbObjectGuid##RegisterUnserializationBehavior(gcmp::IUnserializationBehavior * pBehavior) \
    { \
        gcmp::NdbClassSchemaLibraryOfCode::GetInstance()->RegisterUnserializationBehavior(DbObjectGuid, pBehavior); \
    } \
    class __Class##DbObjectGuid##RegisterUnserializationBehavior {    \
    public:                                                   \
        __Class##DbObjectGuid##RegisterUnserializationBehavior() \
        { \
            __Func##DbObjectGuid##RegisterUnserializationBehavior(pUnserializationBehavior); \
        } \
    }; \
    static __Class##DbObjectGuid##RegisterUnserializationBehavior __Object##DbObjectGuid##RegisterUnserializationBehavior;

// 使用宏方便声明IDbObject的虚函数
#define DBOBJECT_DATA_BEGIN(NS_PREFIX, CLASS_NAME, PARENT_NAME, CLASS_ID, MODULE_NS_PREFIX)               \
    DEFINE_CAST_DERIVED(NS_PREFIX::CLASS_NAME, PARENT_NAME); \
    IDB_DATA_BEGIN_IMP(NS_PREFIX, CLASS_NAME, PARENT_NAME, CLASS_ID, MODULE_NS_PREFIX)

#define DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(NS_PREFIX, CLASS_NAME, PARENT_NAME, CLASS_ID, MODULE_NS_PREFIX, QUICK_CAST_SOURCE)               \
    DEFINE_CAST_DERIVED2(NS_PREFIX::CLASS_NAME,PARENT_NAME, QUICK_CAST_SOURCE); \
    IDB_DATA_BEGIN_IMP(NS_PREFIX, CLASS_NAME, PARENT_NAME, CLASS_ID, MODULE_NS_PREFIX)\

#define DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM_OTHER2(NS_PREFIX, CLASS_NAME, PARENT_NAME, CLASS_ID, MODULE_NS_PREFIX, QUICK_CAST_SOURCE_1, QUICK_CAST_SOURCE_2)               \
    DEFINE_CAST_DERIVED3(NS_PREFIX::CLASS_NAME, PARENT_NAME, QUICK_CAST_SOURCE_1, QUICK_CAST_SOURCE_2); \
    IDB_DATA_BEGIN_IMP(NS_PREFIX, CLASS_NAME, PARENT_NAME, CLASS_ID, MODULE_NS_PREFIX)\

#define DBOBJECT_DATA_END };
